﻿function share_linkhay() { u = location.href; window.open("http://linkhay.com/submit?link_url=" + encodeURIComponent(u)); }
function share_zing() { u = location.href; window.open("http://link.apps.zing.vn/share?u=" + encodeURIComponent(u)); }
function share_govn() { u = location.href; window.open("http://my.go.vn/share.aspx?url=" + encodeURIComponent(u)); }
function share_twitter() { u = location.href; t = document.title; window.open("http://twitter.com/home?status=" + encodeURIComponent(u)); }
function share_facebook() { u = location.href; t = document.title; window.open("http://www.facebook.com/share.php?u=" + encodeURIComponent(u) + "&t=" + encodeURIComponent(t)); }
function share_google() { u = location.href; t = document.title; window.open("http://www.google.com/bookmarks/mark?op=edit&bkmk=" + encodeURIComponent(u) + "&title=" + t + "&annotation=" + t); }
function InputFocus(textdefault, control) { text = control.value; if (text == textdefault) control.value = ""; }
function InputBlur(textdefault, control) { text = control.value; if (text == "") control.value = textdefault; }


function sendMessage() {
    // check valid on client
    if (//validRequireField($("#txtTitle").val(), "Tiêu đề") && 
            validRequireField($("#txtName").val(), "Họ tên")
            && validRequireField($("#txtContent").val(), "Nội dung")
            && validRequireField($("#txtCaptcha").val(), "Mã xác nhận")
            && validEmail($("#txtEmail").val())
            ) {
        $("#btnSend").attr('disabled', 'disabled');

        titleStr = $("#txtTitle").val();
        nameStr = $("#txtName").val();
        emailStr = $("#txtEmail").val();
        addressStr = $("#txtAddress").val();
        phoneStr = $("#txtPhone").val();
        contentStr = $("#txtContent").val();
        captcha = $("#txtCaptcha").val();

        var dataString = "aid=" + aid + "&title=" + titleStr + "&name=" + nameStr + "&email=" + emailStr + "&address=" + addressStr + "&phone=" + phoneStr + "&content=" + contentStr + "&captcha=" + captcha;
        $.ajax({
            type: "POST",
            url: "/handler/update_comment.ashx",
            data: dataString,
            cache: false,
            success: function (data) {
                $("#btnSend").attr('disabled', '');

                if (data == "-1") {
                    alert("Bạn hãy điền đầy đủ thông tin.");
                    return;
                } else if (data == "-2") {
                    alert("Bạn hãy chờ 1 phút để tiếp tục đưa ý kiến.");
                    return;
                } else if (data == "-3") {
                    alert("Bạn hãy điền đúng mã xác nhận trước khi tiếp tục.");
                    return;
                } else {

                    clearBox();

                    alert("Thông tin của bạn đã được gửi.");
                }
                $("#imgCaptcha").attr('src', '/handler/captcha.ashx?' + Math.random());
            }
        });
    }

    return false;
}

function clearBox() {
    $("#txtTitle").val('Tiêu đề');
    $("#txtName").val('Họ tên');
    $("#txtEmail").val('Email');
    $("#txtAddress").val('Địa chỉ');
    $("#txtPhone").val('Điện thoại');
    $("#txtContent").val('Nội dung');
    $("#txtCaptcha").val('');

    return false;
}

function validRequireField(str, name) {

    if ($.trim(str) == "" || $.trim(str) == name) {
        alert(name + " không được để trống.");
        return false;
    }

    return true;
}

function validEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

    if (reg.test(email) == false) {
        alert("Sai định dạng email.");
        return false;
    }

    return true;
}
function getGoldRate() {
    $("#reid").hide();

    var _param = {
        _t: "getRateGold"
    }
    $.ajax({
        type: "GET",
        url: configJs.rootUrl + "handler/getHandler.ashx",
        data: _param,
        // contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var s = '';
            s += '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table1">';
            s += '<tbody><tr>';
            s += '<td align="left" width="40%"><a href="javascript:;">Loại</a></td>';
            s += '<td style="padding:0px;" align="left" width="33%">Giá mua<br />(tr/lượng)</td>';
            s += '   <td style="padding:0px;" align="left" width="20%" class="xanh">Giá bán<br />(tr/lượng)</td>';
            s += '<td style="padding:0px;" align="left" width="20%" class="xanh"></td>';
            s += '</tr></tbody>';
            $.each(data.sort(function (a, b) { return parseInt(a.Id) - parseInt(b.Id) }), function (i, value) {
                s += '<tbody><tr>';
                s += '<td align="left" width="40%"><a href="javascript:;">' + value.Name + '</a></td>';
                s += '<td align="left" width="20%">' + value.PriceBuy + '</td>';
                s += '   <td align="left" width="20%" class="xanh">' + value.PriceSell + '</td>';
                s += '<td align="left" width="20%" class="xanh"></td>';
                s += '</tr></tbody>';

            });
            s += '</table>';
            $("#tg").html(s);

        }
    });

}
function getRatio() {
    $("#reid").show();

    var _param = {
        _t: "getRatio"
    }
    $.ajax({
        type: "GET",
        url: configJs.rootUrl + "handler/getHandler.ashx",
        data: _param,
        //  contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            var s = '';
            s += '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table2">';
            s += '<thead>';
            s += '<tr>';
            s += '  		<td width="25%" rowspan="2" align="left">Ngoại tệ</td>';
            s += '  		<td colspan="2" align="center">Giá mua (VND)</td>';
            s += '  		<td width="25%" rowspan="2" align="center">Giá bán (VND)</td>';
            s += '  	</tr>';
            s += '    <tr>';
            s += '   		<td width="25%" align="center" class="dong_do">TM/Séc</td>';
            s += '  		<td width="25%" align="center" class="dong_do">C.khoán</td>';
            s += '</tr>';

            s += '</thead>';

            $.each(data, function (i, value) {
              
                s += '<tbody>';
                s += '	<tr>';
                s += ' 		<td align="left" width="25%"><a href="javascript:;">' + value.Name + '</a></td>';
                s += '		<td align="center" width="25%">' + value.PriceBuySec + '</td>';
                s += '		<td align="center" width="25%" class="xanh">' + value.PriceBuyCK + '</td>';
                s += '	<td align="center" width="25%" class="xanh">' + value.PriceSell + '</td>';
                s += '	</tr>';
                s += ' </tbody>';
            });

            s += '</table>';
            $("#tg").html(s);
        }
    });

}
function showTab(type, obj) {
    $('div.tygia ul li a.chon1').removeClass('chon1');
    $("#" + obj).addClass("chon1");
    switch (type) {
        case 1: getGoldRate(); break;
        case 2: getRatio(); break;
    }
}
function playvideo(url, imgurl) {

    jwplayer().load([{
        file: 'http://www.youtube.com/watch?v=' + url,
        image: imgurl
    }]);
    jwplayer().play();

}


function formDateTimehms(date) {
    date = date.replace(/\-/g, '\/').replace(/[T|Z]/g, ' ');
    var d = new Date(date);
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();
    var _hour = d.getHours();
    var _minute = d.getMinutes();
    var _second = d.getSeconds();
    if (curr_date < 10) curr_date = "0" + curr_date;
    if (curr_month < 10) curr_month = "0" + (curr_month + 1);
    if (_hour < 10) _hour = "0" + _hour;
    if (_minute < 10) _minute = "0" + _minute;
    return curr_date + "/" + curr_month
        + "/" + curr_year + " " + _hour + ":" + _minute;
}
function formDateTime(date) {
    var d = new Date(date);
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();
    return curr_date + "-" + curr_month
        + "-" + curr_year;
}
